package com.cbg.service.impl;

import com.cbg.mapper.TbItemMapper;
import com.cbg.po.TbItem;
import com.cbg.po.TbItemExample;
import com.cbg.pojo.EUDataGridResult;
import com.cbg.service.inter.ItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenboge on 2017/3/16.
 */
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemMapper mapper;

    @Override
    public EUDataGridResult queryItems(int page, int pagesize) {
        TbItemExample example = new TbItemExample();
        PageHelper.startPage(page, pagesize);
        List<TbItem> items = mapper.selectByExample(example);
        EUDataGridResult result = new EUDataGridResult();
        result.setRows(items);
        PageInfo<TbItem> pageInfo = new PageInfo<>(items);
        result.setTotle(pageInfo.getTotal());
        return result;
    }

}
